package Lee_code;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;

/**
 * @author blh
 * @date 2024年06月30日 9:56
 */
public class Lee_151_630 {
    public String reverseWords(String s) {
        s = s.trim();
        String[] strs = s.split(" ");
        Deque<String> deque = new LinkedList<>();
        for (String str : strs) {
            if (!"".equals(str)) {
                deque.push(str);
            }
        }
        StringBuilder sb = new StringBuilder();
        while (!deque.isEmpty()) {
            sb.append(deque.pop());
            sb.append(" ");
        }
        return sb.toString().trim();
    }
}
